import math
import torch
from torch import nn
import torch
import torch.nn.functional as F

class SoftmaxCrossEntropy(nn.Module):

    def __init__(self):
        super(SoftmaxCrossEntropy, self).__init__()

    def forward(self, y_preds, y_true):
        '''

        :param y_preds: (N,C), Variable of FloatTensor
        :param y_true: (N,C), Variable of FloatTensor
        :return:
        '''
        # print(y_preds.size())
        ylogp = y_true *y_preds

        return -ylogp.sum()/y_true.size(0)
